/*
 * Antenna Rotator 16 kg-m
 * Copyright 2012 John Pritchard
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * units = inches
 */

/*
 * NTA2031
 */
mast_bearing_thrust_height = 0.0781;
/* 
 * R16-2RS
 */
mast_bearing_radial_height = 0.500;
/* 
 * Radial bearings' separator
 */
mast_bearing_spacer_height = 4.0;
/* 
 */
mast_block_od = (2.0-mechtol);

mast_block_height = 0.75;

mast_block_gearmotor_clearance = 0.1;
/* 
 */
mast_tube_od = 2.5;

mast_tube_id = 2.0;

mast_tube_height = 18.0;
/*
 */
mast_block_shaft_offset = (mast_bearing_spacer_height/2)+(mast_bearing_radial_height)+(mast_block_height/2)+(2*mechtol);

mast_bearing_thrust_offset = (mast_block_shaft_offset+(mast_bearing_thrust_height/2)+mechtol);

mast_block_mount_offset = (mast_bearing_spacer_height/2)+(mast_bearing_radial_height)+(mast_block_height/2)+(2*mechtol);

mast_bearing_radial_offset = (mast_bearing_spacer_height/2)+(mast_bearing_radial_height/2)+(mechtol);

mast_gearmotor_offset = ((gearmotor_body_height/2)+(mast_block_height-mast_block_gearmotor_clearance)+(mast_bearing_spacer_height/2)+(mast_bearing_radial_height)+(3*mechtol));

mast_block_support_offset = ((mast_block_height/2)+(gearmotor_body_height-(2*mast_block_gearmotor_clearance))+(mast_block_height)+(mast_bearing_spacer_height/2)+(mast_bearing_radial_height)+(2*mechtol));
/* 
 */
mast_horizontal_axle_od = 1.25;

mast_horizontal_axle_height = 12.0;

mast_horizontal_axle_offset = (mast_horizontal_axle_height/2);
/*
 * TR-031 Hydraulic Rod T-Seal Buna-N
 */
mast_horizontal_axle_seal_od = 2.875;

mast_horizontal_axle_seal_height = 0.28;
/*
 * Contain mast top seal: min 3.125, nom 3.25
 */
mast_horizontal_axle_block_od = 3.75;

mast_horizontal_axle_block_height = head_tube_od+1.5;

mast_horizontal_axle_block_base = 0.5;

mast_horizontal_axle_block_offset = mast_horizontal_axle_block_base;

mast_horizontal_axle_block_bearingsurface = (mast_horizontal_axle_block_height/2)-mast_horizontal_axle_seal_height;
/*
 */
mast_horizontal_axle_bearing_shoulder_od = 1.0;

mast_horizontal_axle_bearing_shoulder_offset = (mast_horizontal_axle_block_bearingsurface+mast_block_height);

mast_horizontal_axle_bearing_shoulder_height = mast_horizontal_axle_height-mast_horizontal_axle_bearing_shoulder_offset;
/* 
 */
mast_horizontal_axle_motor_shoulder_offset = (mast_horizontal_axle_height/2)-(mast_block_height/2);

mast_horizontal_axle_motor_shoulder_od = (gearmotor_mount_shoulder_od-(mechtol*2));
/*
 */
mast_horizontal_axle_assembly_offset = 0.0;

/*
 * Boca NTA2031
 * 1.2520 x 1.9375 x 0.781 in
 */
module mast_bearing_thrust(){
	difference(){
		cylinder(r = (1.9375/2), h = mast_bearing_thrust_height, center = true, $fn = resolution);
		cylinder(r = (1.2520/2), h = mast_bearing_thrust_height, center = true, $fn = resolution);
	}
}
/*
 * Boca R16-2RS
 * 1.0000 x 2.0000 x 0.5000 in
 */
module mast_bearing_radial(){
	difference(){
		cylinder(r = (2.0/2), h = mast_bearing_radial_height, center = true, $fn = resolution);
		cylinder(r = (1.0/2), h = mast_bearing_radial_height, center = true, $fn = resolution);
	}
}
/*
 * Turn 2" Round 6061 to (2.0-mechtol) OD
 */
module mast_block(){

	cylinder(r = (2.0-mechtol)/2, h = mast_block_height, center = true, $fn = resolution);
}
/* 
 * Head mounting block
 */
module mast_horizontal_axle_block(){

	difference(){

		cylinder(r = (mast_horizontal_axle_block_od/2), h = mast_horizontal_axle_block_height, center = true, $fn = resolution);

		translate([0,0,-(mast_horizontal_axle_block_height/2)]){
			cylinder(r = (mast_horizontal_axle_od/2), h = mast_horizontal_axle_block_height, center = true, $fn = resolution);
		}

		translate([0,0,mast_horizontal_axle_block_base]){
			rotate([0,90,0]){
				cylinder(r = (head_tube_od/2), h = mast_horizontal_axle_block_od+1, center = true, $fn = resolution);
			}
		}
		translate([0,0,-(mast_horizontal_axle_block_height/2)+(mast_horizontal_axle_seal_height/2)]){
			/*
			 * (mechtol added to height for cad visual surface cutting)
			 */
			cylinder(r = (mast_horizontal_axle_seal_od/2), h = mast_horizontal_axle_seal_height+mechtol, center = true, $fn = resolution);
		}
	}
}
/*
 */
module mast_horizontal_axle_bearing_shoulder(){
	translate([0,0,-(mast_horizontal_axle_bearing_shoulder_offset)]){
		difference(){
			cylinder( r = (mast_horizontal_axle_od/2)+mechtol, h = mast_horizontal_axle_bearing_shoulder_height, center = true, $fn = resolution);
			cylinder( r = (mast_horizontal_axle_bearing_shoulder_od/2), h = mast_horizontal_axle_bearing_shoulder_height, center = true, $fn = resolution);
		}
	}
}
module mast_horizontal_axle_motor_shoulder(){
	translate([0,0,-(mast_horizontal_axle_motor_shoulder_offset)]){
		difference(){
			cylinder( r = (mast_horizontal_axle_od/2)+mechtol, h = mast_block_height, center = true, $fn = resolution);
			cylinder( r = (mast_horizontal_axle_motor_shoulder_od/2), h = mast_block_height, center = true, $fn = resolution);
		}
	}
}
/* 
 * 
 */
module mast_horizontal_axle(){

	difference(){
		cylinder(r = (mast_horizontal_axle_od/2), h = mast_horizontal_axle_height, center = true, $fn = resolution);

		translate([0,0,+(mast_horizontal_axle_height/2)]){  //(Removes excessive material for correct result)
			rotate([0,90,0]){
				cylinder(r = (head_tube_od/2), h = mast_tube_od, center = true, $fn = resolution);
			}
		}
		mast_horizontal_axle_bearing_shoulder();
		mast_horizontal_axle_motor_shoulder();
	}
}
module mast_horizontal_axle_assembly(){

	translate([0,0,-(mast_horizontal_axle_block_offset)]){

		mast_horizontal_axle_block();
	}
	translate([0,0,-(mast_horizontal_axle_offset)]){

		mast_horizontal_axle();
	}
}
/*
 * Tube 6061 2.0 OD, 0.25 Wall
 */
module mast_bearing_spacer(){
	difference(){
		cylinder(r = (2.0/2), h = mast_bearing_spacer_height, center = true, $fn = resolution);
		cylinder(r = (1.5/2), h = mast_bearing_spacer_height, center = true, $fn = resolution);
	}
}
/*
 * Secondary (outboard) motor mount
 */
module mast_block_support(){
	difference(){
		mast_block();
		translate([0,0,+(mast_block_height/2)-(mast_block_gearmotor_clearance/2)]){
			/*
			 * gearmotor body clearance
			 */
			gearmotor_body((gearmotor_body_radius+mechtol), mast_block_gearmotor_clearance);
		}
		mast_block_mount_taps();
	}
}
/*
 * Primary (inboard) motor mount
 */
module mast_block_mount(){
	difference(){
		mast_block();
		gearmotor_mount(mast_block_height);
		translate([0,0,-(mast_block_height/2)+(mast_block_gearmotor_clearance/2)]){
			/*
			 * gearmotor body clearance: maximize mount strength
			 */
			gearmotor_body((gearmotor_body_radius+mechtol), mast_block_gearmotor_clearance);
		}
		translate([0,0,+(mast_block_height/2)-0.125]){
			/*
			 * Embedded axle clearance
			 */
			cylinder(r = (1.5+(2*mechtol))/2, h = 0.25, center = true, $fn = resolution);
			/*
			 * Mount bolt head clearance 
			 * M4 ALLEN DIN 912
			 * Head Height 4 mm, 0.1575 in; Diameter 7 mm, 0.2756 in
			 *
			 * Flat Washer
			 * Diameter 9mm, 0.3543 in; Height = 0.8 mm, 0.0315 in
			 */
			fastener_m4_mount_tapped(depth = 0.25, expansion = 0.1771);
		}
		translate([0,0,+(mast_block_height/2)-0.25-(0.189/2)]){
			/*
			 * Mount bolt head sink 
			 * M4 ALLEN DIN 912 Head + Flat Washer (4 + 0.8 mm)
			 */
			fastener_m4_mount_tapped(depth = 0.189, expansion = 0.1771);
		}
		mast_block_mount_taps();
	}
}
/*
 * M4 taps with 8 mm depth
 * Minimal interior wall at gearmotor body clearance (diagonal)
 */
module mast_block_mount_taps(depth = 0.315){

	translate([0,0,-0.07]){

		fastener_m4_round_taps( mast_block_od, depth);
	}
}
module mast_block_mount_countersinks(){

	translate([0,0,-0.07]){

		fastener_m4_tube_countersinks( mast_tube_od);
	}
}
module mast_block_shaft(){

	difference(){
		mast_block();
		cylinder(r = (1.5+mechtol)/2, h = mast_block_height, center = true, $fn = resolution);
		mast_block_shaft_taps();
		mast_block_shaft_tseal();
	}
}
/*
 * M4 taps with 5 mm depth
 * Minimal interior wall at gearmotor body clearance (diagonal)
 */
module mast_block_shaft_taps(depth = 0.1969){

	fastener_m4_round_taps( mast_block_od, depth);
}
module mast_block_shaft_countersinks(){

    fastener_m4_tube_countersinks( mast_tube_od);
}
/*
 * Blocks, Bearings, and Spacer
 */
module mast_internal(){

	translate([0,0,+(mast_bearing_thrust_offset)]){
		mast_bearing_thrust();
	}
	translate([0,0,+(mast_block_shaft_offset)]){
		mast_block_shaft();
	}
	translate([0,0,+(mast_bearing_radial_offset)]){
		mast_bearing_radial();
	}
	translate([0,0,0]){
		mast_bearing_spacer();
	}
	translate([0,0,-(mast_bearing_radial_offset)]){
		mast_bearing();
	}
	translate([0,0,-(mast_block_mount_offset)]){
		mast_block_mount();
	}
	translate([0,0,-(mast_block_support_offset)]){
		mast_block_support();
	}
}
module mast_tube(){
	difference(){
		cylinder(r = (mast_tube_od/2), h = mast_tube_height, center = true, $fn = resolution);
		cylinder(r = (mast_tube_id/2), h = mast_tube_height, center = true, $fn = resolution);
	}
}
module mast(){

}
